package com.yeyouluo.bigdata.hadoop;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


public class HomeworkReducer extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {
    private int num = 0;
    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        // sum
        int sum = 0;
        for (IntWritable count : values) {
            sum += count.get();
        }

        // output
        for (int i = 0; i < sum; i++) {
            num++;
            context.write(new IntWritable(num), key);
        }
    }
}